package net.hanjava.swing;

import java.awt.GridLayout;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JPanel;

/**
 * http://hanjava.net/call-151/2008/03/22/jtooltip-%ec%9d%b4%ec%95%bc%ea%b8%b0-i/
 * @author behumble
 *
 */
public class TooltipExample1 {
	// override getTooltipText(MouseEvent)
	static class CustomButton extends JButton {
		public CustomButton(String text) {
			super(text);
			// meaningless value for turning of tooltip
			setToolTipText("position");
		}

		@Override
		public String getToolTipText(MouseEvent e) {
			String msg = String.format("(%d,%d)", e.getX(), e.getY());
			return msg;
		}
	}

	public static void main(String[] args) {
		Util.ensureSwingInit();
		JPanel cp = new JPanel();
		cp.setLayout(new GridLayout(1, 2));
		cp.add(new CustomButton("han"));
		cp.add(new CustomButton("java"));
		Util.show(cp, 100, 100, 300, 300);
	}
}